"use strict";

var Nf = require('../../index'),
    Router = require('../router').Router;

module.exports = function (webModule, route, executor, cb) {
    var pos = executor.lastIndexOf('.');
    if (pos < 0) {
        return cb('Invalid action: ' + executor);
    }

    var controller = executor.substr(0, pos);
    var action = executor.substr(pos + 1);

    var dispatchInfo = {
        controller: controller,
        action: action,
        view: controller + '_' + action
    };

    webModule.routes || (webModule.routes = {});
    webModule.routes[route] = dispatchInfo;

    cb(null, Router.dispatch);
};